package com.focusai.efairy.utils;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
import com.focusai.efairy.R;

/**
 * Created by luo_guangwen on 2017/10/13.
 */

public class ImageLoadUtils {
    public static final int FADE_DURING = 300;
    public static void displayImage(Context mContext, ImageView imageView,String url, RequestOptions options){
        Glide.with(mContext).load(url)
                .transition(DrawableTransitionOptions.withCrossFade(FADE_DURING))
                .apply(options).into(imageView);
    }
    public static void displayImage(Context mContext, ImageView imageView,int drawableId,int defaultId, RequestOptions options){
        Glide.with(mContext).load(drawableId)
                .transition(DrawableTransitionOptions.withCrossFade(FADE_DURING))
                .apply(options.placeholder(defaultId).error(defaultId)).into(imageView);
    }
    public static RequestOptions getOptions() {
        RequestOptions options = new RequestOptions()
                .centerCrop()
                .placeholder(R.drawable.image_default_pic)
                .error(R.drawable.dm_img_forpic_normal)
                .priority(Priority.HIGH)
                .fitCenter()
                .dontAnimate()
                .dontTransform()
                .override(300, 300)
                .diskCacheStrategy(DiskCacheStrategy.ALL);
        return options;
    }
}
